import {deleteAction, getAction, httpAction, postAction, putAction} from '@/api/manage'
import Vue from 'vue'
import {UI_CACHE_DB_DICT_DATA_ERP} from "@/store/mutation-types"

////根路径
// const doMian = "/jeecg-boot/";
////图片预览请求地址
// const imgView = "http://localhost:8080/jeecg-boot/api/erpmng/sys/common/view/";

//角色管理
const addRole = (params) => postAction("/api/erpmng/sys/role/add", params);
const editRole = (params) => putAction("/api/erpmng/sys/role/edit", params);
// const getRoleList = (params)=>getAction("/api/erpmng/sys/role/list",params);
// const deleteRole = (params)=>deleteAction("/api/erpmng/sys/role/delete",params);
// const deleteRoleList = (params)=>deleteAction("/api/erpmng/sys/role/deleteBatch",params);
const checkRoleCode = (params) => getAction("/api/erpmng/sys/role/checkRoleCode", params);
const queryall = (params) => getAction("/api/erpmng/sys/role/queryall", params);

//用户管理
const addUser = (params) => postAction("/api/erpmng/sys/user/add", params);
const editUser = (params) => putAction("/api/erpmng/sys/user/edit", params);
const updateUser = (params) => getAction("/api/erpmng/sys/user/updateUser", params); //更新缓存信息
const queryUserRole = (params) => getAction("/api/erpmng/sys/user/queryUserRole", params);
const getUserList = (params) => getAction("/api/erpmng/sys/user/list", params);
const getUserListOrder = (params) => getAction("/api/erpmng/sys/user/userList", params);
// const deleteUser = (params)=>deleteAction("/api/erpmng/sys/user/delete",params);
// const deleteUserList = (params)=>deleteAction("/api/erpmng/sys/user/deleteBatch",params);
const frozenBatch = (params) => putAction("/api/erpmng/sys/user/frozenBatch", params);
//验证用户是否存在
const checkOnlyUser = (params) => getAction("/api/erpmng/sys/user/checkOnlyUser", params);
//改变密码
const changePassword = (params) => putAction("/api/erpmng/sys/user/changePassword", params);

//权限管理
const addPermission = (params) => postAction("/api/erpmng/sys/permission/add", params);
const editPermission = (params) => putAction("/api/erpmng/sys/permission/edit", params);
const getPermissionList = (params) => getAction("/api/erpmng/sys/permission/list", params);
/*update_begin author:wuxianquan date:20190908 for:添加查询一级菜单和子菜单查询api */
const getSystemMenuList = (params) => getAction("/api/erpmng/sys/permission/getSystemMenuList", params);
const getSystemSubmenu = (params) => getAction("/api/erpmng/sys/permission/getSystemSubmenu", params);
const getSystemSubmenuBatch = (params) => getAction('/api/erpmng/sys/permission/getSystemSubmenuBatch', params)
/*update_end author:wuxianquan date:20190908 for:添加查询一级菜单和子菜单查询api */

// const deletePermission = (params)=>deleteAction("/api/erpmng/sys/permission/delete",params);
// const deletePermissionList = (params)=>deleteAction("/api/erpmng/sys/permission/deleteBatch",params);
const queryTreeList = (params) => getAction("/api/erpmng/sys/permission/queryTreeList", params);
const queryTreeListForRole = (params) => getAction("/api/erpmng/sys/role/queryTreeList", params);
const queryListAsync = (params) => getAction("/api/erpmng/sys/permission/queryListAsync", params);
const queryRolePermission = (params) => getAction("/api/erpmng/sys/permission/queryRolePermission", params);
const saveRolePermission = (params) => postAction("/api/erpmng/sys/permission/saveRolePermission", params);
const queryPermissionsByUsername = (params)=>getAction("/api/erpmng/sys/permission/queryByUser",params);
const queryPermissionsByUser = () => getAction("/api/erpmng/sys/permission/getUserPermissionByToken");
const loadAllRoleIds = (params) => getAction("/api/erpmng/sys/permission/loadAllRoleIds", params);
const getPermissionRuleList = (params) => getAction("/api/erpmng/sys/permission/getPermRuleListByPermId", params);
const queryPermissionRule = (params) => getAction("/api/erpmng/sys/permission/queryPermissionRule", params);

// 部门管理
const queryDepartTreeList = (params) => getAction("/api/erpmng/sys/sysDepart/queryTreeList", params); //查询所有部门（含虚拟部门）
const queryRealDepartTreeList = (params) => getAction("/api/erpmng/sys/sysDepart/queryTreeAndCountList", params);//只查询真实部门（不含虚拟部门）
const queryCompanyTreeList = (params) => getAction("/api/erpmng/sys/sysDepart/queryCompanyTreeList", params);
const queryRealDepartIdTreeList = (params) => getAction("/api/erpmng/sys/sysDepart/queryRealDepartIdTreeList", params);//真实的部门数据
const queryIdTree = (params) => getAction("/api/erpmng/sys/sysDepart/queryIdTree", params);
const queryParentName = (params) => getAction("/api/erpmng/sys/sysDepart/queryParentName", params);
const searchByKeywords = (params) => getAction("/api/erpmng/sys/sysDepart/searchBy", params);//查询所有部门信息
const searchByRealKeywords = (params) => getAction("/api/erpmng/sys/sysDepart/searchRealDepart", params);//查询真实的部门信息
const deleteByDepartId = (params) => deleteAction("/api/erpmng/sys/sysDepart/delete", params);

//二级部门管理
const queryDepartPermission = (params) => getAction("/api/erpmng/sys/permission/queryDepartPermission", params);
const saveDepartPermission = (params) => postAction("/api/erpmng/sys/permission/saveDepartPermission", params);
const queryTreeListForDeptRole = (params) => getAction("/api/erpmng/sys/sysDepartPermission/queryTreeListForDeptRole", params);
const queryDeptRolePermission = (params) => getAction("/api/erpmng/sys/sysDepartPermission/queryDeptRolePermission", params);
const saveDeptRolePermission = (params) => postAction("/api/erpmng/sys/sysDepartPermission/saveDeptRolePermission", params);
const queryMyDepartTreeList = (params) => getAction("/api/erpmng/sys/sysDepart/queryMyDeptTreeList", params);

//日志管理
//const getLogList = (params)=>getAction("/api/erpmng/sys/log/list",params);
const deleteLog = (params) => deleteAction("/api/erpmng/sys/log/delete", params);
const deleteLogList = (params) => deleteAction("/api/erpmng/sys/log/deleteBatch", params);

//数据字典
const addDict = (params) => postAction("/api/erpmng/sys/dict/add", params);
const editDict = (params) => putAction("/api/erpmng/sys/dict/edit", params);
//const getDictList = (params)=>getAction("/api/erpmng/sys/dict/list",params);
const treeList = (params) => getAction("/api/erpmng/sys/dict/treeList", params);
// const delDict = (params)=>deleteAction("/api/erpmng/sys/dict/delete",params);
//const getDictItemList = (params)=>getAction("/api/erpmng/sys/dictItem/list",params);
const addDictItem = (params) => postAction("/api/erpmng/sys/dictItem/add", params);
const editDictItem = (params) => putAction("/api/erpmng/sys/dictItem/edit", params);
//const delDictItem = (params)=>deleteAction("/api/erpmng/sys/dictItem/delete",params);
//const delDictItemList = (params)=>deleteAction("/api/erpmng/sys/dictItem/deleteBatch",params);

//字典标签专用（通过code获取字典数组）
export const ajaxGetDictItems = (code, params) => getAction(`/api/erpmng/sys/dict/getDictItems/${code}`, params);


// 获取系统级字典
export const sysAjaxGetDictItems = (code, params) => getAction(`/api/erpmng/sys/dict/getDictItems/${code}`, params);

// 获取环保管家字典
// export const hmhbAjaxGetDictItems = (code, params) => getAction(`/api/hmhb/dict/getDictItems/${code}`, params);

// ERP
export const erpAjaxGetDictItems = (code, params) => getAction(`/api/erp/dict/getDictItems/${code}`, params);

//IMP
export const impAjaxGetDictItems = (code, params) => getAction(`/api/imp/dict/getDictItems/${code}`, params);
export const serviceAjaxGetDictItems = (tablePrefix, code, params) => getAction(`/api/${tablePrefix}/dict/getDictItems/${code}`, params);

//从缓存中获取字典配置
function getDictItemsFromCache(dictCode) {
  if (Vue.ls.get(UI_CACHE_DB_DICT_DATA_ERP) && Vue.ls.get(UI_CACHE_DB_DICT_DATA_ERP)[dictCode]) {
    let dictItems = Vue.ls.get(UI_CACHE_DB_DICT_DATA_ERP)[dictCode];
    // console.log("-----------getDictItemsFromCache----------dictCode=" + dictCode + "---- dictItems=", dictItems)
    return dictItems;
  }
}

//系统通告
const doReleaseData = (params) => getAction("/api/erpmng/sys/annountCement/doReleaseData", params);
const doReovkeData = (params) => getAction("/api/erpmng/sys/annountCement/doReovkeData", params);
//获取系统访问量
const getLoginfo = (params) => getAction("/api/erpmng/sys/loginfo", params);
const getVisitInfo = (params) => getAction("/api/erpmng/sys/visitInfo", params);
//数据日志访问
// const getDataLogList = (params)=>getAction("/api/erpmng/sys/dataLog/list",params);

// 根据部门主键查询用户信息
const queryUserByDepId = (params) => getAction("/api/erpmng/sys/user/queryUserByDepId", params);

// 查询用户角色表里的所有信息
// const queryUserRoleMap = (params)=>getAction("/api/erpmng/sys/user/queryUserRoleMap",params);
// 重复校验
const duplicateCheck = (params) => getAction("/api/erpmng/sys/duplicate/check", params);
// 加载分类字典
const loadCategoryData = (params) => getAction("/api/erpmng/sys/category/loadAllData", params);
const checkRuleByCode = (params) => getAction('/api/erpmng/sys/checkRule/checkByCode', params)
//加载站点信息
const getSiteInfo = (params) => getAction("/api/erpmng/eoa/cms/eoaCmsSite/getSiteInfo", params);
//加载我的计划信息
const getPlanInfo = (params) => getAction("/api/erpmng/eoa/plan/queryMyCreationByDate", params);
//加载我的通告信息
const getUserNoticeInfo = (params) => getAction("/api/erpmng/sys/sysAnnouncementSend/getMyAnnouncementSend", params);
//查询图表数据
const getChartData = (params) => getAction("/api/erpmng/joa/dataStatistics/getChartDate", params);
const getPieData = (params) => getAction("/api/erpmng/joa/dataStatistics/getPieDate", params);
const getTransitURL = url => `/api/erpmng/sys/common/transitRESTful?url=${encodeURIComponent(url)}`
// 中转HTTP请求
export const transitRESTful = {
  get: (url, parameter) => getAction(getTransitURL(url), parameter),
  post: (url, parameter) => postAction(getTransitURL(url), parameter),
  put: (url, parameter) => putAction(getTransitURL(url), parameter),
  http: (url, parameter) => httpAction(getTransitURL(url), parameter),
}
//查询会议室
const getMettingRoomList = (params) => getAction("/api/erpmng/eoa/metting/eoaMettingRoom/list", params);

//hy 快捷菜单
const queryTreeListByUser = (params) => getAction("/api/erpmng/sys/permission/queryTreeListByUser", params);
const queryUserQuickMenu = (params) => getAction("/api/erpmng/sys/sysQuickMenu/queryUserQuickMenu", params);
const saveQuickMenu = (params) => postAction("/api/erpmng/sys/sysQuickMenu/saveQuickMenu", params);

// 工时填写,,,用于判断是否可以填报，上周已经填了才能填本周，以及已填报则无需再次填报
const checkCanFillIn = (params) => getAction("/api/erp/hours/workmain/erpWorkingHours/canFillIn", params)
// 获取生产人员类型，白名单，生产统筹人员
const getUserTypeByUserId = (params) => getAction("/api/erp/hours/personneltype/erpProductionPersonnelType/getUserTypeByUserId", params)

export {
  // imgView,
  // doMian,
  addRole,
  editRole,
  checkRoleCode,
  addUser,
  editUser,
  updateUser,
  queryUserRole,
  getUserList,
  queryall,
  frozenBatch,
  checkOnlyUser,
  changePassword,
  getPermissionList,
  addPermission,
  editPermission,
  queryTreeList,
  queryListAsync,
  queryRolePermission,
  saveRolePermission,
  queryPermissionsByUsername,
  queryPermissionsByUser,
  loadAllRoleIds,
  getPermissionRuleList,
  queryPermissionRule,
  queryDepartTreeList,
  queryCompanyTreeList,
  queryIdTree,
  queryParentName,
  searchByKeywords,
  deleteByDepartId,
  deleteLog,
  deleteLogList,
  addDict,
  editDict,
  treeList,
  addDictItem,
  editDictItem,
  doReleaseData,
  doReovkeData,
  getLoginfo,
  getVisitInfo,
  queryUserByDepId,
  duplicateCheck,
  queryTreeListForRole,
  getSystemMenuList,
  getSystemSubmenu,
  getSystemSubmenuBatch,
  loadCategoryData,
  checkRuleByCode,
  queryDepartPermission,
  saveDepartPermission,
  queryTreeListForDeptRole,
  queryDeptRolePermission,
  saveDeptRolePermission,
  queryMyDepartTreeList,
  getSiteInfo,
  getUserNoticeInfo,
  getPlanInfo,
  getChartData,
  getPieData,
  getMettingRoomList,
  getDictItemsFromCache,
  queryTreeListByUser,
  queryUserQuickMenu,
  saveQuickMenu,
  queryRealDepartTreeList,
  searchByRealKeywords,
  queryRealDepartIdTreeList,
  getUserListOrder,
  checkCanFillIn,
  getUserTypeByUserId
}



